package org.zyl.util.property;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 获取配置文件配置
 * @author yzzhouyalei@foxmail.com
 * @time 2017-03-09 18:13:43
 */
public class PropertiesUtil {
	public static final String IMAGE_HOST = PropertiesUtil.getPropertiesByKey("image.host", "config.properties");
	public static final String ROUTER_HOST = PropertiesUtil.getPropertiesByKey("router.host", "config.properties");
	public static final String IMAGE_USER_HEAD = PropertiesUtil.getPropertiesByKey("image.user.head", "config.properties");
	public static final String IMAGE_COMPANY_LOGO = PropertiesUtil.getPropertiesByKey("image.company.logo", "config.properties");
	public static final String PATH_INTERFACE = PropertiesUtil.getPropertiesByKey("path.interface", "config.properties");
	
	public static String getPropertiesByKey(String key ,String fileName) {
		InputStream inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName);
		if (inputStream==null) {
			return "";
		}
		Properties p = new Properties();
		try {
			p.load(inputStream);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		return p.getProperty(key);
	}
	
	/**
	 * 指定路径
	 * @author yzzhouyalei@foxmail.com
	 * @time 2017-06-08 11:23:42
	 */
	public static String getPropertiesByKeyAndPath(String key ,String path, String fileName) {
		try {
			InputStream inputStream = new FileInputStream(new File(path+"/"+fileName));
			Properties p = new Properties();
			p.load(inputStream);
//			String system = System.getProperties().getProperty("os.name").toLowerCase();
//			System.out.println(system);
			return p.getProperty(key);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		return "";
	}
}
